package com.itbac.springsecurityoauth2demo.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfiguration;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;

/**
 * 线上，授权服务和资源服务是分开的
 * 资源服务
 * @author: BacHe
 * @email: 1218585258@qq.com
 * @Date: 2021/3/27 12:04
 */
@Configuration
@EnableResourceServer
public class ResourceServerConfig extends ResourceServerConfigurerAdapter{

    @Override
    public void configure(HttpSecurity http) throws Exception {

        http.authorizeRequests()
                //所有访问资源服务器都被拦截
                .anyRequest().authenticated()
                .and()
                //请求匹配
                .requestMatchers()
                //放行访问用户资源
                .antMatchers("/user/**");
    }
}
